package com.cccx.easy;

/**
 * 有效的括号
 */
public class T_20 {

    public static void main(String[] args) {
        System.out.println(judgeBrackets("[{({(){}})}]"));

    }

    public boolean isValid(String s) {
//       System.out.println('(' - ')');
        return judgeBrackets("(]");
    }

    /**
     * 逐一匹配
     * @param str
     * @return
     */
    public static boolean judgeBrackets(String str) {
        if (null != str) {
            int a = str.length();
            for (int i = 0; i <= a / 2 + 1; i++) {
                str = str.replace("()", "")
                        .replace("[]", "")
                        .replace("{}", "");
            }
            System.out.println(str);
            return str.length() == 0;
        }

        return false;
    }
}